package com.ziq.zcamp.api.repository

import com.ziq.zcamp.api.request.topics.TopicsDetailsParam
import com.ziq.zcamp.api.request.topics.TopicsPostParam
import com.ziq.zcamp.api.request.topics.TopicsSearchParam
import com.ziq.zcamp.api.service.request
import com.ziq.zcamp.bean.topics.TopicsDetailsInfo
import com.ziq.zcamp.bean.topics.TopicsInfo
import com.ziq.zcamp.bean.topics.TopicsPostList
import com.ziq.zcamp.manager.GlobalContextManager
import com.ziq.zcamp.manager.ServiceEntryPointManager
import dagger.hilt.android.EntryPointAccessors

class DefaultPostTopicsRepository : PostTopicsRepository {

    override suspend fun topicSearch(keyword: String): List<TopicsInfo> {
        val entryPoint = EntryPointAccessors.fromApplication(
            GlobalContextManager.appContext!!,
            ServiceEntryPointManager::class.java
        )
        val respond = entryPoint.postingService().topicsSearch(
            TopicsSearchParam().apply {
                if (keyword.isNotEmpty()){
                    this.keyword = keyword
                }
        }.queryMap).request()
        return respond.data?.list?: emptyList()
    }

    override suspend fun topicDetails(name: String): TopicsDetailsInfo {
        val entryPoint = EntryPointAccessors.fromApplication(
            GlobalContextManager.appContext!!,
            ServiceEntryPointManager::class.java
        )
        val respond = entryPoint.postingService().topicsDetails(
            TopicsDetailsParam().apply {
                this.name = name
            }.queryMap).request()
        return respond.data?: TopicsDetailsInfo()
    }


}